package models

import "encoding/json"

type Account struct {
	BaseModel
	Name       string    `json:"name" form:"name" gorm:"column:name;unique"`
	Deleted    bool      `json:"deleted" form:"deleted" gorm:"column:deleted"`
	AccessKey  string    `json:"accesskey" binding:"required" form:"accesskey" gorm:"column:access_key"`
	SecretKey  string    `json:"secretkey" binding:"required" form:"secretkey" gorm:"column:secret_key"`
	Active     bool      `json:"active" form:"active" gorm:"column:active"`
	Note       string    `json:"note" binding:"required" form:"note" gorm:"column:note"`
	Level      string    `json:"level" form:"level" gorm:"column:level"`
	Role       string    `json:"role" form:"role" gorm:"column:role"`
	Capital    string    `json:"capital" binding:"required" form:"capital" gorm:"column:capital"`
	CurFund    string    `json:"cur_fund"  form:"cur_fund" gorm:"column:cur_fund"`
	BaseFund   string    `json:"base_fund"  form:"base_fund" gorm:"column:base_fund"`
	Reserved   string    `json:"reserved" form:"reserved" gorm:"column:reserved"`
	MarketId   uint64    `json:"marketId"  form:"marketId" gorm:"column:market_id;default:'galeone'"`
	Market     Market    `json:"-" gorm:"foreignkey:Id;association_foreignkey:MarketId;omitempty"`
	ExchangeId uint64    `json:"exchangeId"  form:"exchangeId" gorm:"column:exchange_id"`
	Exchange   Exchange  `json:"-" gorm:"foreignkey:Id;association_foreignkey:ExchangeId;omitempty"`
	ParentId   uint64    `json:"parentId" form:"parentId" gorm:"column:parent_id;default:'galeone';null"`
	Childs     []Account `json:"childs" form:"childs" gorm:"foreignkey:ParentId;omitempty"`
}

type FakeAccount Account

// 定义序列化的格式
func (a Account) MarshalJSON() ([]byte, error) {

	return json.Marshal(struct {
		FakeAccount
		Market   string `json:"marketName"`
		Exchange string `json:"exchangeName"`
	}{
		FakeAccount: FakeAccount(a),
		Market:      a.Market.Name,
		Exchange:    a.Exchange.Name})
}
